<?php
	/**
	 * Created by PhpStorm.
	 * User: mybook-lhp
	 * Date: 18/7/9
	 * Time: 下午2:43
	 */

	namespace app\member\admin;


	use app\admin\controller\Admin;
	use app\common\builder\ZBuilder;
	use app\member\model\MemberInfoModel;

	class Identity extends Admin
	{
		public function index()
		{
			// 查询
			$map = $this->getMap();

			// 排序
			$order = $this->getOrder('mi.admin_pass_time desc');

			$btnCheck = [
				'class' => 'btn btn-info',
				'title' => '审核',
				'icon'  => 'fa fa-fw fa-sitemap',
				'href'  => url('check', ['id' => '__member_id__'])
			];

			// 数据列表
			$member_list = MemberInfoModel::IdentityList($map, $order);
			//dump(\db('')->getLastSql());die;
			// 使用ZBuilder快速创建数据表格
			return ZBuilder::make('table')
				->setSearch(['phone' => '手机号码'])// 设置搜索框
				->addColumns([ // 批量添加数据列
							   ['id', 'ID'],
							   ['nickName', '昵称', 'text'],
							   ['true_name', '姓名', 'text'],
							   ['user_card_hold', '手持身份证', 'text'],
							   ['user_card_z', '身份证正面', 'text'],
							   ['user_card_f', '身份证反面', 'text'],

							   ['admin_remarks', '审核备注', 'text'],
							   ['admin_status', '审核状态', 'text', '', [1 => '审核中', 0 => '没有认证', 2 => '失败', 3 => '通过']],
							   ['right_button', '操作', 'btn']
				])
				//->addTopButtons('enable,disable')// 批量添加顶部按钮
				->addRightButtons(['check' => $btnCheck])// 批量添加右侧按钮
				//->addOrder('id,phone,create_time,update_time')
				->setRowList($member_list)// 设置表格数据
				->fetch(); // 渲染模板
		}

		public function check($id = null)
		{
			if ($id === null)
				$this->error('缺少参数', 'index');

			// 保存数据
			if ($this->request->isPost())
			{
				// 表单数据
				$data = $this->request->post();

				// 验证
				$result = $this->validate($data, 'Link');
				if (true !== $result)
					$this->error($result);

				if (MemberInfoModel::update($data))
				{
					// 记录行为
					action_log('link_edit', 'cms_link', $id, UID, $data['title']);
					$this->success('编辑成功', 'index');
				} else
				{
					$this->error('编辑失败');
				}
			}

			$info = MemberInfoModel::IdentityInfo($id);

			// 显示编辑页面
			return ZBuilder::make('form')
				->addFormItems([
					['hidden', 'id'],
					['static', 'nickName', '用户昵称'],
					['static', 'true_name', '用户姓名'],
					['gallery', 'user_card_hold', '手持身份证'],
					['gallery', 'user_card_z', '身份证正面'],
					['gallery', 'user_card_f', '身份证反面'],
					['static', 'admin_status', '审核备注'],
					['text', 'admin_remarks', '审核状态'],
					['radio', 'status', '是否通过审核', '', ['否', '是']]
				])
				->setTrigger('type', 2, 'logo')
				->setFormData($info)
				->fetch();
		}
	}